<template>
  <div class="allFeatures">
    <div>
      <div class="filter-all">
        <div class="filter-list"
             v-show="routerList != null"
             v-for="routerItem in routerList"
             :key="routerItem.featuresId"
             :class="{ filterClass: filterId == routerItem.featuresId }"
             @click="changefil(routerItem)">
          <router-link :to="{
            name: 'allFeatures',
            query: {
              titleId: $route.query.titleId,
              busTypeId: $route.query.busTypeId,
              featuresId: routerItem.featuresId,
              osTypeId: $route.query.osTypeId,
              osVersionId: $route.query.osVersionId,
            },
          }">{{ routerItem.name }}</router-link>
        </div>
      </div>
      <div class="test-content-list">
        <div class="subjectClass"
             :class="((index+1)%3) === 0 ? 'noPadding' : ''"
             v-for="(item, index) in list"
             :key="item.id">
          <div class="left-name"
               @click="toDetail(item)">
            <div class="left-content">
              <div class="left-title">
                <img v-if="item.sign == 1"
                     class="burning"
                     src="../assets/images/fat-burning.png" />
                <div class="left-name">{{ item.name }}</div>
                <img class="arrow-right"
                     src="../assets/images/arrow_right.png" />
              </div>
              <div class="left-main">
                {{ item.summary }}
              </div>
              <div class="left-btn left-num">
                <span> {{ item.typeName }} </span>
              </div>
            </div>
          </div>
        </div>
        <div class="waiting"
             v-if="list == null">待开放</div>
      </div>
      <div v-show="list && list.length>0">
        <Pagination class="pagination"
                    @changeCurrentPage="changeCurrentPage"
                    :total="totalNum"
                    :pageSize="pageSize"
                    :continuePages="3"
                    :currentPageWrap="pageNo">
        </Pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { mapActions, mapState } from "vuex";
import Pagination from "./commonComponent/pagination.vue";
export default {
  components: { Pagination },
  data () {
    return {
      activeIndex: "1",
      activeIndex2: "1",
      filterId: "0",
      pageSize: 9,
      pageNo: 1,
      levelList: 1,
      titleList: 1,
      featuresId: null,
      busTypeId: null,
      titleId: 1,
      osTypeId: null,
      osVersionId: null,
      // routerList: [{ name: "全部特性全部特性", featuresId: 79 }],
    };
  },
  computed: {
    ...mapState({
      routerList: (state) => state.initData.featuresList,
      list: (state) => state.initData.sampleList,
      totalNum: (state) => state.initData.totalNum,
    }),
  },
  created () {
    this.search(this.pageNo, null);
  },

  methods: {
    ...mapActions(["setBreadcrumb", "getPageData"]),
    async search (pageNo, featuresId) {
      if (this.$route.query.pageNum) {
        this.pageNo = this.$route.query.pageNum;
      }
      if (this.$route.query.busTypeId) {
        this.busTypeId = this.$route.query.busTypeId;
      }
      if (this.$route.query.titleId) {
        this.titleId = this.$route.query.titleId;
      }
      if (this.$route.query.osTypeId) {
        this.osTypeId = this.$route.query.osTypeId;
      }
      if (this.$route.query.osVersionId) {
        this.osVersionId = this.$route.query.osVersionId;
      }

      let params = {
        busTypeId: this.busTypeId,
        titleId: this.titleId,
        osTypeId: this.osTypeId,
        osVersionId: this.osVersionId,
        pageNum: pageNo,
        pageSize: this.pageSize,
      }
      if (typeof (this.featuresId) === 'number' && this.featuresId !== 0 || this.featuresId) params.featuresId = featuresId

      let res = await this.$axios.get(
        "/knowledge/frontPage/queryInitialization", { params }
      );
      if (res.data.code == 0) {
        let busTypeList = res.data.data.busTypeList;
        let featuresList = res.data.data.featuresList;
        let sampleList = res.data.data.sampleList;
        let titleList = res.data.data.titleList;
        let osTypeList = res.data.data.osTypeList;
        let osVersionList = res.data.data.osVersionList;
        let pageNum = this.pageNo;
        let pageSize = this.pageSize;
        let totalNum = res.data.totalNum;
        //设置面包屑
        // busTypeList &&
        //   busTypeList.length > 0 &&
        //   this.setBreadcrumb({ type: "bustype", ...busTypeList[0] });
        osTypeList.unshift({
          osTypeId: "0",
          name: "全部",
          sort: "1",
        });
        osVersionList.unshift({
          osVersionId: "0",
          name: "全部",
          sort: "1",
        });
        this.getPageData({
          busTypeList,
          featuresList,
          sampleList,
          titleList,
          osTypeList,
          osVersionList,
          pageSize,
          pageNum,
          totalNum,
        });
      }
    },

    handleSelect (key, keyPath) {
      console.log(key, keyPath);
    },
    handleSelectBtn (key, keyPath) {
      console.log(key, keyPath);
    },
    handleOpen (key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose (key, keyPath) {
      console.log(key, keyPath);
    },
    changefil (item) {
      this.filterId = item.featuresId;
      this.featuresId = item.featuresId;
      this.pageNo = 1;
      if (this.$route.query.busTypeId) {
        this.busTypeId = localStorage.getItem("busTypeId");
      }
      // this.busTypeId = localStorage.getItem("busTypeId");
      this.search(this.pageNo, this.featuresId);
    },
    toDetail (item) {
      localStorage.setItem("sampleId", item.sampleId);
      let routeData = this.$router.resolve({ name: "detail", query: { sampleId: item.sampleId } });
      window.open(routeData.href, '_blank')

      this.setBreadcrumb({ type: "detail", ...item });
    },
    changeCurrentPage (pageNo = 1) {
      this.pageNo = pageNo;
      this.search(this.pageNo, this.featuresId);
    },
  },
  // watch: {
  //   routerList: {
  //     handler(newVal) {
  //       this.routerList = newVal;
  //       console.log("新值", newVal);
  //     },
  //   },
  // },
};
</script>
<style lang="less" scoped>
.filter-all {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  width: 35%;
  .filter-list {
    a {
      padding: 0 5px;
      color: #000000;
      display: inline-block;
      min-width: 50px;
      max-width: 100px;
      height: 31px;
      line-height: 31px;
      word-break: keep-all;
      background: #f3f3f3;
      border-radius: 15px;
      margin-top: 32px;
      text-align: center;
      font-size: 14px;
      margin-right: 10px;
      padding: 0 16px;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      border: 1px solid #f3f3f3;
    }
  }
  .filterClass {
    a {
      height: 31px;
      line-height: 31px;
      border: 1px solid #328dff;
      background-color: rgba(227, 240, 255, 1);
      font-family: HarmonyOS_Sans_SC_Medium;
      color: #328dff;
    }
  }
}
.test-content-list {
  width: 1180px;
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  flex-wrap: wrap;
  height: 100%;
  .subjectClass {
    width: 376px;
    height: 100%;
    height: 201px;
    // max-height: 402px;
    background: #fafafa;
    border-radius: 16px;
    margin-top: 24px;
    margin-right: 20px;
    border: 1px solid #fafafa;
    cursor: pointer;
    // border: 1px solid black;
    .left-content {
      position: relative;
      padding-top: 49px;
      padding-left: 16px;
      padding-bottom: 40px;
      .left-title {
        display: flex;
        flex-direction: row;
        // height: 22px !important;
        // // max-height: 44px;
        .burning {
          height: 28px;
        }
        .left-name {
          font-size: 24px;
          height: 24px;
          line-height: 24px;
          // display: inline-block;
          width: 60% !important;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
          opacity: 0.9;
        }
      }
      .left-main {
        width: 87%;
        margin-top: 14px;
        margin-bottom: 8px;
        height: 44px;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow: hidden;
        // max-height: 132px;
        font-size: 14px;
        line-height: 22px;
        color: #333333;
        opacity: 0.9;
      }
      .left-btn {
        width: 85%;
        margin-top: 8px;
        height: 22px;
        font-size: 12px;
        font-family: HarmonyOS_Sans_SC_Light;
        color: #000000;
        opacity: 0.6;
        line-height: 22px;
      }
      .arrow-right {
        // width: 30px;
        height: 30px;
        position: absolute;
        top: 42px;
        right: 20px;
      }
    }
  }
  .subjectClass:hover {
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.06);
    box-shadow: 0px 2px 14px 0px rgba(0, 0, 0, 0.04);
  }
  .noPadding {
    margin-right: 0 !important;
  }
  .waiting {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    line-height: 11;
    font-size: 18px;
    color: gray;
  }
}
.pagination {
  width: 77.5%;
  margin: 16px 0;
}
@media screen and (min-width: 1441px) and (max-width: 1920px) {
  .left-name {
    font-size: 24px;
  }
}
@media screen and (min-width: 721px) and (max-width: 1440px) {
  .left-name {
    font-size: 24px;
  }
}
@media screen and (max-width: 540px) {
  .filter-all {
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    width: 100%;
    height: 33px;
    margin: 16px 0;
    -webkit-overflow-scrolling: touch;
    overflow-x: auto;
    overflow-y: hidden;
    &::-webkit-scrollbar {
      display: none;
    }
    .filter-list {
      a {
        // min-width: 50px;
        color: #000000;
        opacity: 0.6;
        width: auto;
        height: 31px;
        background: #f3f3f3;
        border-radius: 18px;
        line-height: 31px;
        // text-align: center;
        font-size: 14px;
        margin: 0 12px;
      }
      ::v-deep a {
        color: #000000;
      }
      a {
        line-height: 31px;
        text-decoration: none;
        display: inline-block;
        height: inherit;
        width: inherit;
        border: 1px solid #f3f3f3;
      }
    }
    .filterClass {
      ::v-deep a {
        display: block;
        border-radius: 18px;
        height: 31px;
        background-color: rgba(227, 240, 255, 1);
        border: 1px solid #328dff;
        height: 31px;
        font-size: 14px;
        font-family: HarmonyOS_Sans_SC_Medium;
        color: #328dff;
        line-height: 31px;
        opacity: 1;
      }
    }
  }
  .test-content-list {
    width: 100% !important;
    // border: 1px solid #0b226d;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    flex-wrap: wrap;
    height: 100%;
    // max-height: 1000px;
    // overflow: auto;
    .subjectClass {
      width: 351px;
      max-width: 100%;
      // min-height: 164px;
      height: 164px;
      margin: 0 12px;
      background: #fafafa;
      border-radius: 16px;
      margin-top: 12px;
      cursor: pointer;
      // border: 1px solid black;
      .left-content {
        position: relative;
        padding-top: 28px;
        padding-left: 16px;
        padding-bottom: 24px;
        .burning {
          width: 28px;
          height: 28px;
        }
        .left-title {
          font-size: 24px;
          span {
            width: 253px;
            height: 22px;
          }
        }
        .left-main {
          height: 44px;
          font-size: 14px;
          line-height: 22px;
        }
        .left-btn {
          height: 22px;
          font-size: 12px;
          font-family: HarmonyOS_Sans_SC_Light;
          color: #000000;
          opacity: 0.6;
          line-height: 22px;
        }
        .arrow-right {
          width: 30px;
          height: 29px;
          position: absolute;
          top: 30px;
          right: 19px;
        }
      }
    }
    .subjectClass:nth-child(1) {
      margin-top: 0;
    }
    .waiting {
      width: 100%;
      height: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
      line-height: 11;
      font-size: 18px;
      color: gray;
    }
  }
  .pagination {
    margin: 16px 0;
    width: 361px;
  }
}
</style>
